﻿using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.Collections.Generic;

namespace PRI_SliverlightSS
{
    public class PRI_Album_Info
    {
        public string _id = string.Empty;
        public string _title = string.Empty;
        public string _content_url = string.Empty;
        public string _thumbnail_url = string.Empty;
        public string _published_datetime = string.Empty;
    }

    public class PRI_Slide_Thumb
    {
        public string _url = string.Empty;
        public double _height = 0;
        public double _width = 0;
    }

    public class PRI_Slide
    {
        public int _index = -1;
        public string _id = string.Empty;
        public string _title = string.Empty;
        public string _content_url = string.Empty; //Main Image. Big one
        public string _description = string.Empty;

        public PRI_Slide_Thumb _thumb_small = new PRI_Slide_Thumb();
        public PRI_Slide_Thumb _thumb_medium = new PRI_Slide_Thumb();
        public PRI_Slide_Thumb _thumb_large = new PRI_Slide_Thumb();

        public void SetThumb(PRI_Slide_Thumb _thumb)
        {
            //ascending order. Fill small->medium->large
            if (_thumb_small._height == 0)
            {
                //Small
                _thumb_small._url = _thumb._url;
                _thumb_small._height = _thumb._height;
                _thumb_small._width = _thumb._width;
            }
            else if (_thumb_medium._height == 0)
            {
                //Medium
                _thumb_medium._url = _thumb._url;
                _thumb_medium._height = _thumb._height;
                _thumb_medium._width = _thumb._width;
            }
            else
            {
                //Large
                _thumb_large._url = _thumb._url;
                _thumb_large._height = _thumb._height;
                _thumb_large._width = _thumb._width;
            }
        }

        public FrameworkElement _FrameworkElement = null;
        public int _page = 0;
        public bool _thumb_loaded = false;
    }

    public class PRI_Slides
    {
        private int m_CurrentIndex;

        public List<PRI_Slide> _slides = null;

        public PRI_Slides()
        {
            _slides = new List<PRI_Slide>(); 
        }

        public void AddPhoto(PRI_Slide _photo)
        {
            _photo._index = _slides.Count;
            _slides.Add(_photo);
        }

        public void Clear()
        {
            _slides.Clear();
            m_CurrentIndex = 0;
        }

        public bool IsEmpty
        {
            get
            {
                return (_slides.Count > 0) ? false : true;
            }
        }

        public void SetFirstIndex()
        {
            m_CurrentIndex = 0;
        }

        public void Skip_N_Indexes(int n) //+ or - OK
        {
            int iNextCurrent = m_CurrentIndex + n;
            
            if (iNextCurrent < 0)
            {
                m_CurrentIndex = 0;
            }
            else if ( iNextCurrent < _slides.Count)
            {
                m_CurrentIndex = iNextCurrent;
            }
            else
            {
                iNextCurrent = 0;
            }
        }

        public void SetLastIndex()
        {
            if (_slides.Count > 0)
            {
                m_CurrentIndex = _slides.Count - 1;
            }
            else
            {
                m_CurrentIndex = 0;
            }
        }

        public void SetNextIndex()
        {
            if (_slides.Count <= 0) { return; }

            m_CurrentIndex++;

            if (_slides.Count <= m_CurrentIndex)
            {
                m_CurrentIndex = 0;
            }
        }

        public void SetPrevIndex()
        {
            if (_slides.Count <= 0) { return; }

            m_CurrentIndex--;

            if (0 > m_CurrentIndex)
            {
                m_CurrentIndex = _slides.Count-1;
            }
        }

        public int _CurrentIndex
        {
            get
            {
                return m_CurrentIndex;
            }
            set
            {
                m_CurrentIndex = value;
            }
        }
    }

}
